package com.weetop.cfw.other

import android.os.Bundle
import android.view.View
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.blankj.utilcode.util.ActivityUtils
import com.weetop.cfw.R
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import kotlinx.android.synthetic.main.activity_audio_detail_web_view.*

/**
 * 音频详情界面
 */
class AudioDetailWebViewActivity : CommonBaseActivity(),View.OnClickListener {

    override fun onClick(p0: View?) {
        when(p0?.id){
            R.id.imageAudioDetailBack,R.id.textAudioDetailBack -> {
                ActivityUtils.finishActivity(this)
            }
        }
    }

    override fun getLayoutId() = R.layout.activity_audio_detail_web_view

    override fun initView(savedInstanceState: Bundle?) {
        setViewsOnClickListener(this,imageAudioDetailBack,textAudioDetailBack)
       initWebView()
    }

    override fun initData(savedInstanceState: Bundle?) {

    }

    private fun initWebView(){
        audioDetailWebView.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                return false// 返回false
            }
        }
        val webSettings = audioDetailWebView.settings
        // 让WebView能够执行javaScript
        webSettings.javaScriptEnabled = true
        // 让JavaScript可以自动打开windows
        webSettings.javaScriptCanOpenWindowsAutomatically = true
        // 设置缓存
        webSettings.setAppCacheEnabled(true)
        // 设置缓存路径
//        webSettings.setAppCachePath("")
        // 支持缩放(适配到当前屏幕)
        webSettings.setSupportZoom(true)
        // 将图片调整到合适的大小
        webSettings.useWideViewPort = true
        // 支持内容重新布局,一共有四种方式
        // 默认的是NARROW_COLUMNS
        webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        // 设置可以被显示的屏幕控制
        webSettings.displayZoomControls = true
        // 设置默认字体大小
        webSettings.defaultFontSize = 12
        audioDetailWebView.loadUrl("https://www.jd.com/?cu=true&utm_source=baidu-pinzhuan&utm_medium=cpc&utm_campaign=t_288551095_baidupinzhuan&utm_term=0f3d30c8dba7459bb52f2eb5eba8ac7d_0_5975df7466f740e096eb7eb3fb13dacf")
    }

}
